package com.smartthinking.CICPNL.home.activity;

import java.util.ArrayList;
import java.util.Dictionary;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.smartthinking.CICPNL.R;
import com.smartthinking.CICPNL.R.id;
import com.smartthinking.CICPNL.home.activity.Eventos.Eventos_Adapter;
import com.smartthinking.CICPNL.home.objects.App_ImageLoader;
import com.smartthinking.CICPNL.home.objects.clsDictionary;
import com.smartthinking.CICPNL.home.objects.clsPrograma;
import com.smartthinking.CICPNL.home.xml.saxXML;


public class Programa extends Activity {

	public int Cont = 1;
	public static ArrayList<Dictionary> ActividadesBanner = null;
	public static ArrayList<Dictionary> BannersActividades = null;
	public static ArrayList<Dictionary> Actividades = null;
	public Dialog progressDialog;
	public Gallery gallery1;
	public Eventos_Adapter myAdapter;
	public App_ImageLoader imageLoader;

	private Dictionary dic = null;
	public ListView list;
	public Hoteles_Adapter adapter;

	private String sFecha = "-";
	private Intent intent;
	private String PUTQRY;
	public static ArrayList<Dictionary<String, String>> TraeDatos = null, DatosPublish;
	public Integer EVEIDR;
	public Utilities findEve;
	public Utilities util;
	public ScrollView scroll_programa, scroll_favoritos;
	public Button btn_todos, btn_favoritos;
	public TextView txtbusqueda;
	private boolean favoritos = false;
	public static ArrayList<Dictionary<String,String>> Splash = null;

	private String strPonente;
	private String busqueda;
	int anuncio_actual = 0;

	public void voidFinish(View V) {
		finish();
	}

	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);
		// Checks the orientation of the screen
	}

	public void abrirMenuLateral(View V) {
		intent = new Intent(Programa.this, MenuLateral.class);
		startActivity(intent);
	}

	@Override
	public void onBackPressed() {
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.ui_programa);

		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		EVEIDR = Utilities.EVE_IDR;
		
		Intent intent = getIntent();
	    strPonente = intent.getStringExtra("PONENTE");
	    if(strPonente == null){
	    	strPonente = "";
	    }
	    if(strPonente.equals("null")){
	    	strPonente = "";
	    }

	    //splash
	    try{
	    	String qry = "select a.* from eventos_banners a inner join banners_catalogo b on a.ban_idr = b.ban_idr where a.eve_idr = "+EVEIDR+" and b.ban_nombre = 'SPLASH PROGRAMA' ORDER BY b.ban_nombre";
	    	Splash = Utilities.qry2(getApplicationContext(), qry);

	    	if(Splash.size()>0){
	    		Dictionary<String, String> dic = Splash.get(0);
	    		String strPoster = dic.get("ban_url").toString();
	    		String strTimer = dic.get("ban_timer").toString();
	    		String strPatrocinador = dic.get("pat_idr").toString();
	    		if (strPoster.equals("null")) {
	    			strPoster = "";
	    		}
	    		if(strPoster.length()>0){
	    			intent = new Intent(Programa.this, Splash2.class);
	    			Bundle bund = new Bundle();
	    			bund.putString("PUT_IMG",strPoster);
	    			bund.putString("PUT_PAT",strPatrocinador);
	    			bund.putString("PUT_TIME",strTimer);
	    			intent.putExtras(bund);
	    			startActivity(intent);
	    		}
	    	}
	    }catch(Exception ex){}

		TextView titulo = (TextView) findViewById(R.id.tv_listView_Titulo);
		scroll_programa = (ScrollView) findViewById(R.id.scroll_programa);
		scroll_favoritos = (ScrollView) findViewById(R.id.scroll_favoritos);
		btn_todos = (Button) findViewById(R.id.iv_btn_todos);
		btn_favoritos = (Button) findViewById(R.id.iv_btn_favoritos);
		txtbusqueda = (TextView) this.findViewById(id.et_buscar_buscar);
		txtbusqueda.setOnKeyListener(new OnKeyListener() {
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				// If the event is a key-down event on the "enter" button
				if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
						(keyCode == KeyEvent.KEYCODE_ENTER)) {
					CargarContenido();

					return true;
				}
				return false;
			}
		});

	    titulo.setText(getString(R.string.modulo_programa));
		CargarContenido();
	}

	public void fFavoritos(View v){
		Button btnf = (Button) findViewById(R.id.iv_btn_favoritos);
		Button btnt = (Button) findViewById(R.id.iv_btn_todos);
		if (favoritos){
			btnf.setBackgroundResource(R.drawable.lst_btn_favoritos_des);
			btnt.setBackgroundResource(R.drawable.lst_btn_todos_act);
			favoritos = false;
		}else{
			btnf.setBackgroundResource(R.drawable.lst_btn_favoritos_act);	
			btnt.setBackgroundResource(R.drawable.lst_btn_todos_des);
			favoritos = true;
		}
		CargarContenido();
	}
	
	private void  muestra_detalle(String idponencia){
		intent = new Intent(this, ProgramaDetalle.class);
		Bundle bund = new Bundle();
		bund.putString("idponencia",idponencia);
		intent.putExtras(bund);
		startActivity(intent);
	}

	private void CargarContenido() {
		new AsyncContenido().execute("");
	}
	
	public void borrar(View v){
		EditText txtbusc = (EditText) findViewById(id.et_buscar_buscar);
		txtbusc.setText("");
		buscar();
	}
	
	public void buscar(){
		String strBusqueda = ((EditText) findViewById(id.et_buscar_buscar)).getText().toString().trim();
		if(!strBusqueda.equals(busqueda)){
			busqueda = strBusqueda;
			CargarContenido();
		}
	}
	
	private class AsyncContenido extends AsyncTask<String, String, String>{
		
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			progressDialog = ProgressDialog.show(Programa.this, "",getResources().getString(R.string.msg_cargando));
		}

		@Override
		protected String doInBackground(String... params) {
			String qrypublicidad = "select a.*, '' as nen_fecha from eventos_banners a inner join banners_catalogo b on a.ban_idr=b.ban_idr " +
					"where a.eve_idr=1 and b.ban_nombre in('BANNER PROGRAMASOC 1','BANNER PROGRAMASOC 2','BANNER PROGRAMASOC 3')ORDER BY b.ban_nombre";

			busqueda = txtbusqueda.getText().toString().trim();
			
		    String strFavoritos = "";
		    if (favoritos) {
		    	Utilities util = new Utilities();
		        strFavoritos =util.getFavoritos(Programa.this,"PONENCIA");
		        if (strFavoritos.length()>0) {
		            strFavoritos = "and nen_idr in("+strFavoritos+")";
		        }else{
		            strFavoritos = "and nen_idr in(9999999)";
		        }
		    }
			
			String qry="";
			if(strPonente.length()<=0){
				if(busqueda.length()<=0){
					Log.i("ponente 0","busqueda 0");
					qry  = "select nen_idr, nen_fecha, nen_inicio, nen_fin, nen_lugar, nen_titulo, nen_titulo_en, nen_lugar_en, nen_ponente " +
							" from ponencias where eve_idr=" + EVEIDR + " "+strFavoritos+" order by nen_fecha, nen_inicio, nen_lugar";
				}else{
					Log.i("ponente 0","busqueda 1");
					qry  = "select nen_idr, nen_fecha, nen_inicio, nen_fin, nen_lugar, nen_titulo, nen_titulo_en, nen_lugar_en, nen_ponente " + 
							" from ponencias where eve_idr = "+EVEIDR+" and ( " + 
							" upper(nen_titulo) like upper('%" + busqueda + "%')  " + 
							" or upper(nen_titulo_en) like upper('%" + busqueda + "%')  " + 
							" or upper(nen_descripcion) like upper('%" + busqueda + "%')  " + 
							" or upper(nen_descripcion_en) like upper('%" + busqueda + "%')  " + 
							" or upper(nen_ponente) like upper('%" + busqueda + "%')  " + 
							" or upper(nen_institucion) like upper('%" + busqueda + "%')  " + 
							" or upper(nen_especialidad) like upper('%" + busqueda + "%')  " + 
							" or upper(nen_especialidad_en) like upper('%" + busqueda + "%') " + 
							" ) "+strFavoritos+" order by nen_fecha, nen_inicio, nen_lugar";
				}
			}else{
				if(busqueda.length()<=0){
					Log.i("ponente 1","busqueda 0");
					qry  = "select a.nen_idr, a.nen_fecha, a.nen_inicio, a.nen_fin, a.nen_lugar, a.nen_titulo, a.nen_titulo_en, a.nen_lugar_en, a.nen_ponente " + 
							" from ponencias a inner join ponentes_ponencias b on a.nen_idr = b.nen_idr " + 
							" where b.pon_idr = " + strPonente + " and a.eve_idr = " + EVEIDR + " "+strFavoritos+" order by nen_fecha, nen_inicio, nen_lugar";
				}else{
					Log.i("ponente 1","busqueda 1");
					qry  = "select a.nen_idr, a.nen_fecha, a.nen_inicio, a.nen_fin, a.nen_lugar, a.nen_titulo, a.nen_titulo_en, a.nen_lugar_en, a.nen_ponente " + 
							" from ponencias a inner join ponentes_ponencias b on a.nen_idr = b.nen_idr " + 
							" where b.pon_idr = " + strPonente + " and a.eve_idr = " + EVEIDR + "  and (" + 
							" upper(nen_titulo) like upper('%" + busqueda + "%') " + 
							" or upper(nen_titulo_en) like upper('%" + busqueda + "%') " + 
							" or upper(nen_descripcion) like upper('%" + busqueda + "%') " + 
							" or upper(nen_descripcion_en) like upper('%" + busqueda + "%') " + 
							" or upper(nen_ponente) like upper('%" + busqueda + "%') " + 
							" or upper(nen_institucion) like upper('%" + busqueda + "%') " + 
							" or upper(nen_especialidad) like upper('%" + busqueda + "%') " + 
							" or upper(nen_especialidad_en) like upper('%" + busqueda + "%')" + 
							" )"+strFavoritos+" order by nen_fecha, nen_inicio, nen_lugar";
				}
			}

			TraeDatos = Utilities.qry3(getApplicationContext(), qry);			
			DatosPublish = Utilities.qry2(getApplicationContext(), qrypublicidad);

			return null;
		}
		
		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			
			generateUI();			
			progressDialog.dismiss();
		}
		
	}
	
	public View.OnClickListener getListener(final String pat_idr){
		return new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent goPatrocinador = new Intent(Programa.this, PatrocinadoresDetalle.class);
				Log.i("pat_idr", ""+pat_idr);
				goPatrocinador.putExtra("idpatrocinador", ""+pat_idr);
				startActivity(goPatrocinador);				
			}
		};
	}
	
	public void generateUI() {
		Log.i("publish size", ""+DatosPublish.size());
		int numanuncios = DatosPublish.size();
		int anuncio_actual = 0;
		int contadorpublicidad = 0;
		int contadorpublicidadzero = 0;
		int flagzero = 0;
		int resolution = 0;
		
		LinearLayout ll_items = (LinearLayout) findViewById(R.id.ll_items);
		ll_items.removeAllViews();
		HorizontalScrollView hs_items = new HorizontalScrollView(this);
		hs_items.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		hs_items.setFillViewport(true);
		LinearLayout ll_hs_items = new LinearLayout(this);
		ll_hs_items.setOrientation(LinearLayout.HORIZONTAL);
		ll_hs_items.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		int flag = 0;
		Dictionary dic = null;
		Dictionary dicnext = null;
		DisplayMetrics metrics = this.getResources().getDisplayMetrics();
		int width = metrics.widthPixels;
		int height = metrics.heightPixels;
		
		for(int i=0; i<(TraeDatos.size()); i++){
		    dic = TraeDatos.get(i);
		    if(i<(TraeDatos.size()-1)){
			    dicnext = TraeDatos.get(i+1);
		    }else{
		    	/*********VERIFICAR PARA EL ULTIMO ELEMENTO*********/
		    	dicnext = TraeDatos.get(i);
		    }
		    if(dic.get("nen_inicio").toString().equals(dicnext.get("nen_inicio").toString())){
		    	RelativeLayout rl_single_item = new RelativeLayout(this);
		    	rl_single_item.setLayoutParams(new LayoutParams(width, LayoutParams.WRAP_CONTENT));
		    	rl_single_item.setOnClickListener(new MyOnClickListener(dic.get("nen_idr").toString()));
		    	LinearLayout ll_single_item = new LinearLayout(this);
			    ll_single_item.setOrientation(LinearLayout.VERTICAL);
			    /*****TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES***/
			    if((resolution = Utilities.getScreenSize(Programa.this)) == 1)
			    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 60));
			    if((resolution = Utilities.getScreenSize(Programa.this)) == 2)
			    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 105));
			    if((resolution = Utilities.getScreenSize(Programa.this)) == 3)
			    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 140));
			    ll_single_item.setBackgroundResource(R.drawable.prog_fondo);
				TextView txt_titulo = new TextView(this);
				TextView txt_ponente = new TextView(this);
				TextView txt_hora = new TextView(this);
				TextView txt_lugar = new TextView(this);
				ImageView im_hora = new ImageView(this);
				ImageView im_lugar = new ImageView(this);
				ImageView im_separator = new ImageView(this);
				LinearLayout ll_hora_lugar = new LinearLayout(this);
				ll_hora_lugar.setOrientation(LinearLayout.HORIZONTAL);
				ll_hora_lugar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
				txt_titulo.setLayoutParams(new LayoutParams((width-20), LayoutParams.WRAP_CONTENT));
				
				String titulo,lugar;
				if(Utilities.IDIOMA.equals("espa�ol")){
					titulo = dic.get("nen_titulo").toString();
					lugar = dic.get("nen_lugar").toString();
				}else{
					titulo = dic.get("nen_titulo_en").toString();
					lugar = dic.get("nen_lugar_en").toString();
				}
				
				txt_titulo.setText(titulo);
				txt_titulo.setTextColor(Color.WHITE);
				txt_titulo.setMaxLines(1);
				txt_ponente.setText(dic.get("nen_ponente").toString());
				txt_ponente.setTextColor(Color.WHITE);
				txt_ponente.setMaxLines(1);
				txt_hora.setText(dic.get("nen_inicio").toString() + " - " + dic.get("nen_fin").toString());
				txt_hora.setTextColor(Color.WHITE);
				txt_lugar.setText(lugar);
				txt_lugar.setTextColor(Color.WHITE);
			    //TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
				if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
					im_hora.setLayoutParams(new LayoutParams(18, 18));
					im_lugar.setLayoutParams(new LayoutParams(18, 18));
				}
				if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
					im_hora.setLayoutParams(new LayoutParams(27, 27));
					im_lugar.setLayoutParams(new LayoutParams(27, 27));
				}
				if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
					im_hora.setLayoutParams(new LayoutParams(36, 36));
					im_lugar.setLayoutParams(new LayoutParams(36, 36));
				}
				im_hora.setImageResource(R.drawable.prog_bullet_hora);
				im_lugar.setImageResource(R.drawable.prog_bullet_salon);
			    //TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
			    if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
			    	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 60);
					params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
					im_separator.setImageResource(R.drawable.prog_separador);
					im_separator.setLayoutParams(params);
			    }
			    if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
			    	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 105);
					params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
					im_separator.setImageResource(R.drawable.prog_separador);
					im_separator.setLayoutParams(params);
			    }
			    if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
			    	RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 140);
					params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
					im_separator.setImageResource(R.drawable.prog_separador);
					im_separator.setLayoutParams(params);
			    }
				ll_hora_lugar.addView(im_hora);
				ll_hora_lugar.addView(txt_hora);
				ll_hora_lugar.addView(im_lugar);
				ll_hora_lugar.addView(txt_lugar);
				ll_single_item.addView(txt_titulo);
				ll_single_item.addView(txt_ponente);
				ll_single_item.addView(ll_hora_lugar);
				rl_single_item.addView(ll_single_item);
				rl_single_item.addView(im_separator);
				ll_hs_items.addView(rl_single_item);
				flag = 1;
		    }else{
		    	if(flag == 1){
		    		contadorpublicidad++;
		    		contadorpublicidadzero++;
			    	LinearLayout ll_single_item = new LinearLayout(this);
				    ll_single_item.setOrientation(LinearLayout.VERTICAL);
			    	ll_single_item.setOnClickListener(new MyOnClickListener(dic.get("nen_idr").toString()));
				    //TAMA�O DE ACUERDO A DENSIDAD DE PIXELES
			    	/*****TAMA�O DE ACUERDO A DENSIDAD DE PIXELES***/
				    if((resolution = Utilities.getScreenSize(Programa.this)) == 1)
				    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 60));
				    if((resolution = Utilities.getScreenSize(Programa.this)) == 2)
				    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 105));
				    if((resolution = Utilities.getScreenSize(Programa.this)) == 3)
				    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 140));
				    ll_single_item.setBackgroundResource(R.drawable.prog_fondo);
					TextView txt_titulo = new TextView(this);
					TextView txt_ponente = new TextView(this);
					TextView txt_hora = new TextView(this);
					TextView txt_lugar = new TextView(this);
					ImageView im_hora = new ImageView(this);
					ImageView im_lugar = new ImageView(this);
					LinearLayout ll_hora_lugar = new LinearLayout(this);
					ll_hora_lugar.setOrientation(LinearLayout.HORIZONTAL);
					ll_hora_lugar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
					txt_titulo.setLayoutParams(new LayoutParams((width-20), LayoutParams.WRAP_CONTENT));
					
					String titulo,lugar;
					if(Utilities.IDIOMA.equals("espa�ol")){
						titulo = dic.get("nen_titulo").toString();
						lugar = dic.get("nen_lugar").toString();
					}else{
						titulo = dic.get("nen_titulo_en").toString();
						lugar = dic.get("nen_lugar_en").toString();
					}
					
					txt_titulo.setText(titulo);
					txt_titulo.setTextColor(Color.WHITE);
					txt_titulo.setMaxLines(1);
					txt_ponente.setText(dic.get("nen_ponente").toString());
					txt_ponente.setTextColor(Color.WHITE);
					txt_ponente.setMaxLines(1);
					txt_hora.setText(dic.get("nen_inicio").toString() + " - " + dic.get("nen_fin").toString());
					txt_hora.setTextColor(Color.WHITE);
					txt_lugar.setText(lugar);
					txt_hora.setTextColor(Color.WHITE);
				    //TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
					if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
						im_hora.setLayoutParams(new LayoutParams(18, 18));
						im_lugar.setLayoutParams(new LayoutParams(18, 18));
					}
					if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
						im_hora.setLayoutParams(new LayoutParams(27, 27));
						im_lugar.setLayoutParams(new LayoutParams(27, 27));
					}
					if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
						im_hora.setLayoutParams(new LayoutParams(36, 36));
						im_lugar.setLayoutParams(new LayoutParams(36, 36));
					}
					im_hora.setImageResource(R.drawable.prog_bullet_hora);
					im_lugar.setImageResource(R.drawable.prog_bullet_salon);
					ll_hora_lugar.addView(im_hora);
					ll_hora_lugar.addView(txt_hora);
					ll_hora_lugar.addView(im_lugar);
					ll_hora_lugar.addView(txt_lugar);
					ll_single_item.addView(txt_titulo);
					ll_single_item.addView(txt_ponente);
					ll_single_item.addView(ll_hora_lugar);
					ll_hs_items.addView(ll_single_item);
		    		Log.i("items per scroll", ""+ll_hs_items.getChildCount());
					hs_items.addView(ll_hs_items);
					if(flagzero == 0){
						LinearLayout ll_back_date = new LinearLayout(this);
						ll_back_date.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
						ll_back_date.setBackgroundResource(R.drawable.lst_div);
//						ll_back_date.setBackgroundColor(0xFE2E2E);
						TextView txt_date = new TextView(this);
						txt_date.setTextColor(Color.parseColor("#A7005F"));
						txt_date.setText(dic.get("nen_fecha").toString());
						txt_date.setTypeface(null,Typeface.BOLD);
						ll_back_date.addView(txt_date);
						ll_items.addView(ll_back_date);
						flagzero++;
					}
		    		ll_items.addView(hs_items);
		    		
		    		if(dicnext.get("nen_fecha").toString().equals("lastRegister")){
		    			
		    		}else{
		    			if(!(dic.get("nen_fecha").toString().equals(dicnext.get("nen_fecha").toString()))){
					    	contadorpublicidad = 0;
					    	
					    	LinearLayout ll_back_date = new LinearLayout(this);
					    	ll_back_date.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
							ll_back_date.setBackgroundResource(R.drawable.lst_div);
					    	TextView txt_date = new TextView(this);
							txt_date.setTextColor(Color.parseColor("#A7005F"));
					    	txt_date.setText(dicnext.get("nen_fecha").toString());
							txt_date.setTypeface(null,Typeface.BOLD);
					    	ll_back_date.addView(txt_date);
					    	ll_items.addView(ll_back_date);
					    }
		    		}
		    		
				    

			    	BitmapFactory.Options options = new BitmapFactory.Options();
			    	options.inSampleSize = 2;
		    		
				    //addpublicity
				    if(contadorpublicidadzero == 1){
				    	contadorpublicidad = 0;
				    	LinearLayout ll_foto = new LinearLayout(this);
				    	
				    	//TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 50));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));
					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 50);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
//					    	Utilities util = new Utilities();
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 105));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));
					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 105);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 140));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));
					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 140);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
				    	ll_items.addView(ll_foto);
				    	anuncio_actual++;
				    	if(anuncio_actual == numanuncios)
				    		anuncio_actual = 0;
				    }
		    		
		    		if(contadorpublicidad == 3){
				    	LinearLayout ll_foto = new LinearLayout(this);
				    	//TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 50));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));
					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 50);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 105));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));
					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 105);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    	
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 140));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));
					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 140);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
		    			ll_items.addView(ll_foto);
		    			contadorpublicidad = 0;
		    			anuncio_actual++;
		    			if(anuncio_actual == numanuncios)
		    				anuncio_actual = 0;
		    		}
		    		
			    	hs_items = new HorizontalScrollView(this);
					hs_items.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
					hs_items.setFillViewport(true);
					ll_hs_items = new LinearLayout(this);
					ll_hs_items.setOrientation(LinearLayout.HORIZONTAL);
					ll_hs_items.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
					flag = 0;
		    	}else{
		    		contadorpublicidad++;
		    		contadorpublicidadzero++;
				    LinearLayout ll_single_item = new LinearLayout(this);
				    ll_single_item.setOrientation(LinearLayout.VERTICAL);
			    	ll_single_item.setOnClickListener(new MyOnClickListener(dic.get("nen_idr").toString()));
				    //TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
			    	/*****TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES***/
				    if((resolution = Utilities.getScreenSize(Programa.this)) == 1)
				    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 60));
				    if((resolution = Utilities.getScreenSize(Programa.this)) == 2)
				    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 105));
				    if((resolution = Utilities.getScreenSize(Programa.this)) == 3)
				    	ll_single_item.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 140));
				    ll_single_item.setBackgroundResource(R.drawable.prog_fondo);
					TextView txt_titulo = new TextView(this);
					TextView txt_ponente = new TextView(this);
					TextView txt_hora = new TextView(this);
					TextView txt_lugar = new TextView(this);
					ImageView im_hora = new ImageView(this);
					ImageView im_lugar = new ImageView(this);
					LinearLayout ll_hora_lugar = new LinearLayout(this);
					ll_hora_lugar.setOrientation(LinearLayout.HORIZONTAL);
					ll_hora_lugar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
					txt_titulo.setLayoutParams(new LayoutParams((width-20), LayoutParams.WRAP_CONTENT));
					
					String titulo,lugar;
					if(Utilities.IDIOMA.equals("espa�ol")){
						titulo = dic.get("nen_titulo").toString();
						lugar = dic.get("nen_lugar").toString();
					}else{
						titulo = dic.get("nen_titulo_en").toString();
						lugar = dic.get("nen_lugar_en").toString();
					}
					
					txt_titulo.setText(titulo);
					txt_titulo.setTextColor(Color.WHITE);
					txt_titulo.setMaxLines(1);
					txt_ponente.setText(dic.get("nen_ponente").toString());
					txt_ponente.setTextColor(Color.WHITE);
					txt_ponente.setMaxLines(1);
					txt_hora.setText(dic.get("nen_inicio").toString() + " - " + dic.get("nen_fin").toString());
					txt_hora.setTextColor(Color.WHITE);
					txt_lugar.setText(lugar);
					txt_lugar.setTextColor(Color.WHITE);
				    //TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
					if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
						im_hora.setLayoutParams(new LayoutParams(18, 18));
						im_lugar.setLayoutParams(new LayoutParams(18, 18));
					}
					if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
						im_hora.setLayoutParams(new LayoutParams(27, 27));
						im_lugar.setLayoutParams(new LayoutParams(27, 27));
					}
					if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
						im_hora.setLayoutParams(new LayoutParams(36, 36));
						im_lugar.setLayoutParams(new LayoutParams(36, 36));
					}
					im_hora.setImageResource(R.drawable.prog_bullet_hora);
					im_lugar.setImageResource(R.drawable.prog_bullet_salon);
					ll_hora_lugar.addView(im_hora);
					ll_hora_lugar.addView(txt_hora);
					ll_hora_lugar.addView(im_lugar);
					ll_hora_lugar.addView(txt_lugar);
					ll_single_item.addView(txt_titulo);
					ll_single_item.addView(txt_ponente);
					ll_single_item.addView(ll_hora_lugar);
					if(flagzero == 0){
						LinearLayout ll_back_date = new LinearLayout(this);
						ll_back_date.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
				    	ll_back_date.setBackgroundResource(R.drawable.lst_div);
						TextView txt_date = new TextView(this);
						txt_date.setTextColor(Color.parseColor("#A7005F"));
						txt_date.setText(dic.get("nen_fecha").toString());
						txt_date.setTypeface(null,Typeface.BOLD);
						
						ll_back_date.addView(txt_date);
						ll_items.addView(ll_back_date);
						flagzero++;
					}
					ll_items.addView(ll_single_item);
					
		    		if(dicnext.get("nen_fecha").toString().equals("lastRegister")){
		    			
		    		}else{
					    if(!(dic.get("nen_fecha").toString().equals(dicnext.get("nen_fecha").toString()))){
					    	contadorpublicidad = 0;
					    	LinearLayout ll_back_date = new LinearLayout(this);
					    	ll_back_date.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
					    	ll_back_date.setBackgroundResource(R.drawable.lst_div);
					    	TextView txt_date = new TextView(this);
							txt_date.setTextColor(Color.parseColor("#A7005F"));
					    	txt_date.setText(dicnext.get("nen_fecha").toString());
							txt_date.setTypeface(null,Typeface.BOLD);
					    	ll_back_date.addView(txt_date);
					    	ll_items.addView(ll_back_date);
					    }
		    		}
					

				    

			    	BitmapFactory.Options options = new BitmapFactory.Options();
			    	options.inSampleSize = 2;
					
				    //addpublicity
				    if(contadorpublicidadzero == 1){
				    	contadorpublicidad = 0;
				    	LinearLayout ll_foto = new LinearLayout(this);
				    	
				    	//TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 50));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));

					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 50);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 105));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));

					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 105);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 140));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));

					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 140);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
				    	ll_items.addView(ll_foto);
				    	anuncio_actual++;
				    	if(anuncio_actual == numanuncios)
				    		anuncio_actual = 0;
				    }
					
		    		if(contadorpublicidad == 3){
				    	LinearLayout ll_foto = new LinearLayout(this);
				    
				    	//TAMAÑO DE ACUERDO A DENSIDAD DE PIXELES
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 1){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 50));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));

					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 50);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 2){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 105));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));

					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 105);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    	
					    }
					    if((resolution = Utilities.getScreenSize(Programa.this)) == 3){
					    	ll_foto.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 140));
					    	ImageView foto = new ImageView(this);
					    	foto.setOnClickListener(getListener(""+DatosPublish.get(anuncio_actual).get("pat_idr")));
					    	LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 140);
					    	p.weight = 1;
					    	foto.setLayoutParams(p);
					    	Bitmap bm = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory()+"/Pediatria/"+DatosPublish.get(anuncio_actual).get("ban_url"), options);
					    	foto.setImageBitmap(bm);
//					    	Utilities util = new Utilities();
//					    	util.qryImg(this, DatosPublish.get(anuncio_actual).get("ban_url").toString(),foto);
					    	ll_foto.addView(foto);
					    }
		    			ll_items.addView(ll_foto);
		    			contadorpublicidad = 0;
		    			anuncio_actual++;
		    			if(anuncio_actual == numanuncios)
		    				anuncio_actual = 0;
		    		}
		    	}
		    }
		}
	}
	
	private class MyOnClickListener implements OnClickListener {
		String nen_idr;
		public MyOnClickListener(String id) {
			nen_idr = id;
		}
		
		@Override
		public void onClick(View v) {
//			muestra_detalle(TraeDatos.get(nen_idr).get("nen_idr").toString());
//			Toast.makeText(getApplicationContext(), "nen_idr "+nen_idr, Toast.LENGTH_LONG).show();
			muestra_detalle(nen_idr);

		}
	}

	private class AsyncActividades extends AsyncTask<String, Void, Integer> {

		protected void onPostExecute(Integer in) {
			list = (ListView) findViewById(R.id.list);
			adapter = new Hoteles_Adapter(ActividadesBanner);
			list.setAdapter(adapter);
			list.setTextFilterEnabled(true);
			list.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {

					// Intent intent = new Intent(Programa.this,
					// ProgramaDetalle.class);
					// //
					// clsPrograma.setDctionary(ActividadesBanner.get(position));
					// //
					// startActivity(intent);
					//
					// // finish();
					//
					//

					try {
						if (ActividadesBanner.get(position).get("ban_idr").toString().trim().length() > 0) {
							Intent intent1 = new Intent(Programa.this,PatrocinadoresDetalle.class);
							clsDictionary.setDctionary(ActividadesBanner.get(position));
							startActivity(intent1);
						}
					} catch (Exception e) {
						intent = new Intent(Programa.this,ProgramaDetalle.class);
						clsPrograma.setDctionary(ActividadesBanner.get(position));
						startActivity(intent);
						// finish();
					}
				}
			});
			progressDialog.dismiss();
			// abrirSplashBanner();
		}

		protected void onPreExecute() {
			progressDialog = ProgressDialog.show(Programa.this, "","Cargando...");
		}

		@SuppressWarnings("rawtypes")
		protected Integer doInBackground(String... urls) {
			String qry_url = PUTQRY;
			saxXML saxparser = new saxXML(qry_url);
			Actividades = saxparser.parse();

			// select a.* from eventos_banners a inner join banners_catalogo b
			// on a.ban_idr = b.ban_idr where a.eve_idr =
			// "+ dic.get("eve_idr").toString() + " and b.ban_nombre = 'SPLASH
			// PROGRAMA' ORDER BY b.ban_nombre"

			ActividadesBanner = new ArrayList<Dictionary>();
			
			Bundle extras = getIntent().getExtras();
			if (extras == null) {
				qry_url = getString(R.string.QRY_URL)
						+ Uri.encode("select a.* from eventos_banners a inner join banners_catalogo b on a.ban_idr = b.ban_idr where a.eve_idr = "
								+ dic.get("eve_idr").toString()
								+ " and b.ban_nombre in ('BANNER PROGRAMA 1','BANNER PROGRAMA 2','BANNER PROGRAMA 3') ORDER BY b.ban_nombre");

				saxparser = new saxXML(qry_url);

				BannersActividades = saxparser.parse();
				ActividadesBanner = new ArrayList<Dictionary>();

				// // 3 - 6 -9 -12
				//
				// if (position % 3 == 0) {
				// /** Insert banner **/
				//
				//
				// } else {

				

				if (BannersActividades.size() > 0) {
					int cont = 0;
					for (int i = 0; i < Actividades.size(); i++) {
						if (i > 0) {
							if (i % 2 == 0) {
								/** Insert banner **/
								// if (i > 0) {
								try {
									ActividadesBanner.add(BannersActividades.get(cont));
									cont++;
									if (cont == 3)
										cont = 0;
									// }
								} catch (Exception e) {
									cont = 0;
									ActividadesBanner.add(BannersActividades.get(cont));
								}
							}
						}
						ActividadesBanner.add(Actividades.get(i));
					}
				} else {
					ActividadesBanner = Actividades;
				}
			}else {
				ActividadesBanner = Actividades;
			}

			return null;

		}

	}

	public class Hoteles_Adapter extends BaseAdapter {

		private LayoutInflater inflater = null;
		private ArrayList<Dictionary> data;

		public Hoteles_Adapter(ArrayList<Dictionary> d) {

			data = d;
			inflater = (LayoutInflater) Programa.this
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			imageLoader = new App_ImageLoader(
					Programa.this.getApplicationContext());

		}

		public int getCount() {
			return data.size();
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public class ViewHolder {

			public TextView tvTitulo;
			public TextView tvSubtitulo;
			public TextView tvHora;

			public TextView tvFecha;

			public ImageView fondorojo;
			// public ImageView vermas;

			public ImageView banner;

		}

		public View getView(int position, View convertView, ViewGroup parent) {

			View vi = convertView;
			ViewHolder holder;

			if (convertView == null) {

				vi = inflater.inflate(R.layout.ui_programa_items, null);

				holder = new ViewHolder();
				holder.tvTitulo = (TextView) vi.findViewById(R.id.tv_programa_items_titulo);
				holder.tvSubtitulo = (TextView) vi.findViewById(R.id.tv_programa_items_salon);
				holder.tvHora = (TextView) vi.findViewById(R.id.tv_programa_items_hora);

				// @+id/iv_listview_items_imagen
				// holder.icon = (ImageView) vi
				// .findViewById(id.iv_listview_items_imagen);

				holder.banner = (ImageView) vi.findViewById(id.iv_programa_items_banner);
				holder.fondorojo = (ImageView) vi.findViewById(id.imageView2);
				//holder.tvFecha = (TextView) vi.findViewById(id.tv_programa_item_fecha);

				// holder.vermas = (ImageView)
				// vi.findViewById(id.iv_items_vermas);

				vi.setTag(holder);

			} else

				holder = (ViewHolder) vi.getTag();

			/** Insert banner **/
			// ActividadesBanner.add(BannersHoteles.get(0));
			// ban_url

			if (data.get(position).get("ban_url") != null) {
				holder.tvTitulo.setText("");
				holder.tvSubtitulo.setText("");
				holder.tvHora.setText("");
				holder.tvFecha.setText("");
				holder.fondorojo.setVisibility(holder.fondorojo.INVISIBLE);

				try {
					holder.banner.setVisibility(holder.banner.VISIBLE);

					String url_img = getString(R.string.QRY_URL_IMG)
							+ data.get(position).get("ban_url").toString()
									.replace(" ", "%20");

					holder.banner.setTag(url_img);

					imageLoader.DisplayImage(url_img, Programa.this,holder.banner);
					// holder.icon.setVisibility(holder.icon.GONE);
					// holder.vermas.setVisibility(holder.vermas.GONE);

				} catch (Exception ex) {

					String s = ex.getMessage().toString();

				}

			} else {

				holder.banner.setVisibility(holder.banner.GONE);
				//
				// holder.icon.setVisibility(holder.icon.VISIBLE);
				//
				// holder.vermas.setVisibility(holder.vermas.VISIBLE);

				if (position == 0) {
					try {

						sFecha = data.get(position).get("nen_fecha").toString();

						holder.fondorojo
								.setVisibility(holder.fondorojo.VISIBLE);
						holder.tvFecha.setText(sFecha);
					} catch (Exception e) {
					}
				} else {
					if (sFecha.equals(data.get(position).get("nen_fecha")
							.toString())) {

						holder.tvFecha.setText("");
						holder.fondorojo
								.setVisibility(holder.fondorojo.INVISIBLE);

					} else {

						try {
							sFecha = data.get(position).get("nen_fecha")
									.toString();

							holder.fondorojo
									.setVisibility(holder.fondorojo.VISIBLE);
							holder.tvFecha.setText(sFecha);
						} catch (Exception e) {

						}
					}
				}

				try {
					String Titulo;
					if(Utilities.IDIOMA.equals("espa�ol")){
						Titulo = data.get(position).get("nen_titulo").toString();	
					}else{
						Titulo = data.get(position).get("nen_titulo_en").toString();
					}
					holder.tvTitulo.setText(Titulo);
				} catch (Exception e) {

				}
				try {
					String Hora = data.get(position).get("nen_inicio")
							.toString();
					holder.tvHora.setText(Hora);
				} catch (Exception e) {

				}
				try {
					String Salon;
					if(Utilities.IDIOMA.equals("espa�ol")){
						Salon = data.get(position).get("nen_lugar").toString();	
					}else{
						Salon = data.get(position).get("nen_lugar_en").toString();
					}
					
					holder.tvSubtitulo.setText(Salon);
				} catch (Exception e) {

				}
			}

			return vi;

		}
	}

	public void fTodos(View v){
		Button btnf = (Button) findViewById(R.id.iv_btn_favoritos);
		Button btnt = (Button) findViewById(R.id.iv_btn_todos);
		if (btnt.getTag() == "0"){
			btnt.setBackgroundResource(R.drawable.lst_btn_todos_act);	
			btnt.setTag("1");
			btnf.setBackgroundResource(R.drawable.lst_btn_favoritos_des);
			btnf.setTag("0");
		}else{
			btnt.setBackgroundResource(R.drawable.lst_btn_todos_des);
			btnt.setTag("0");
			btnf.setBackgroundResource(R.drawable.lst_btn_favoritos_act);	
			btnf.setTag("1");
		}
	}
	



	
	public void detalle(View v){
		intent = new Intent(this, ProgramaDetalle.class);
		startActivity(intent);
	}
	
	public void voidbusqueda(View v){
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
		
		CargarContenido();
	}
	
	
	
}
